<template>
  <h1>轮播图添加</h1>
  <hr />
  <el-radio-group v-model="labelPosition" label="label position">
    <el-radio-button label="left">Left</el-radio-button>
    <el-radio-button label="right">Right</el-radio-button>
    <el-radio-button label="top">Top</el-radio-button>
  </el-radio-group>
  <div style="margin: 20px" />
  <el-form
    :label-position="labelPosition"
    label-width="100px"
    :model="formLabelAlign"
    style="max-width: 460px"
  >
    <el-form-item label="图片链接">
      <el-input v-model="formLabelAlign.img" />
    </el-form-item>
    <el-form-item label="图片名称">
      <el-input v-model="formLabelAlign.alt" />
    </el-form-item>
    <el-form-item label="图片提示">
      <el-input v-model="formLabelAlign.link" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">添加</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import "element-plus/dist/index.css";
// 导入添加轮播图的请求
import { banner_add } from "../../../utils/api";
const labelPosition = ref("top");
const formLabelAlign = reactive({
  img: "",
  alt: "",
  link: "",
});

// 添加图片信息
const onSubmit = () => {
  if (formLabelAlign.img === "") {
    ElMessage.error("输入框不能为空");
  } else {
    banner_add(formLabelAlign).then((res) => {
      if (res.data.code === "200") {
        ElMessage({
          message: "数据添加成功！",
          type: "success",
        });
      }
    });
  }
};
</script>

<style>
</style>